package demo2;

import java.util.Scanner;

/**
 * @Author liangzai
 * @Description:
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int q = scanner.nextInt();
        while((q--)>0){
            int a2 = scanner.nextInt()*2;
            int a3 = scanner.nextInt()*3;
            int a4 = scanner.nextInt()*4;
            int b4 = scanner.nextInt()*4;
            int b6 = scanner.nextInt()*6;
            int sum = a2+a3+a4;
            int tmp = 0;
            if(a3%6==0){
                if(a3>=b6){
                    //sum += a3-b6;
                    a3 -= b6;
                    b6 = 0;
                }else {
                    //sum += b6-a3;
                    b6 -= a3;
                    a3 = 0;
                }
            }else {
                int x = a3/6;
                int y = b6/6;
                if(x>=y){
                    //sum += y*6;
                    y = 0;
                    a3 -= y*6;
                }else {
                    //sum += x*6;
                    a3 -= x*6;
                    b6 -= x*6;
                }
            }
            if(a4>=b4){
                //sum += a4-b4;
                a4 -= b4;
                b4 = 0;
                if(a4/4>=b6/6){
                    int x = a4/4;
                    int y = b6/6;
                    //sum += y*4;
                    b6 -= y*4;
                    a4 -= y*4;
                    int z = x-y;
                    if(a2>0){
                        //sum += Math.min(a2,b6);
                        a2-=b6;
                    }
                }else {
                    int x = a4%4;
                    int y = b6%6;
                    //sum += b6-a4;
                    a4 = 0;
                    int z = y-x;
                    b6 = z*6;
                    if(a2>=x*2){
                        a2 -= x*2;
                    }else {
                        a2=0;
                    }
                }
            }else {
                //sum += b4-a4;
                b4 -= a4;
                a4 = 0;
            }
            while((a2/2)-3>0&&b6/6>0){
                a2 -= 6;
                b6 -= 6;
            }
            while((a2/2)-2>0&&b4/4>0){
                a2 -= 4;
                b4 -= 4;
            }
            if(a3>0&&b6>0){
                a3 -= 3;
                b6 -= 3;
                if (a2 > 0) {
                    a2 -= 2;
                }
            }
            if(a3/3>=b4/4){
                int key = (a3/3-b4/4);
                a3 -= key*3;
            }else {
                a3 = 0;
            }
            while(a2>0&&b4>2){
                a2-=2;
                a4-=2;
            }
            while(a2>0&&b6>2){
                a2-=2;
                b6-=2;
            }
            sum = sum-a2-a3-a4;
            System.out.println(sum);
        }
    }

    public static void main1(String[] args) {
        Scanner sc=new Scanner(System.in);
        int lie=sc.nextInt();
        while(lie-->0) {
            int a2=sc.nextInt();
            int a3=sc.nextInt();
            int a4=sc.nextInt();
            int b4=sc.nextInt();
            int b6=sc.nextInt();
            int sum=0;
            //满座匹配4人寝坐4人桌
            while(b4>0&&a4>=1) {
                b4--;a4--;sum+=4;
            }
            //满座匹配2x2人寝坐4人桌
            while(b4>0&&a2>=2) {
                b4--;a2-=2;sum+=4;
            }
            //满座匹配2+4人寝坐6人桌
            while(b6>0&&a4>=1&&a2>=1) {
                b6--;a4--;a2--;sum+=6;
            }
            //满座匹配2x3人寝坐6人桌
            while(b6>0&&a3>=2) {
                b6--;a3-=2;sum+=6;
            }
            //满座匹配3x2人寝坐6人桌
            while(b6>0&&a2>=3) {
                b6--;a2-=3;sum+=6;
            }
            //空1座匹配2+3人寝坐6人桌
            while(b6>0&&a2>=1&&a3>=1) {
                b6--;a2--;a3--;sum+=5;
            }
            //空1座匹配3人寝坐4人桌
            while(b4>0&&a3>0) {
                b4--;a3--;sum+=3;
            }
            //空2座匹配2x2人寝坐6人桌
            while(b6>0&&a2>=2) {
                b6--;a2-=2;sum+=4;
            }
            //空2座匹配4人寝坐6人桌
            while(b6>0&&a4>0) {
                b6--;a4--;sum+=4;
            }
            //空2座匹配2人寝坐4人桌
            while(b4>0&&a2>0) {
                b4--;a2--;sum+=2;
            }
            //空3座匹配3人寝坐6人桌
            while(b6>0&&a3>0) {
                b6--;a3--;sum+=3;
            }
            //空4座匹配2人寝坐6人桌
            while(b6>0&&a2>0) {
                b6--;a2--;sum+=2;
            }
            System.out.println(sum);
        }
    }
}





